﻿Public Class UtilityDateTime

	Public Shared Function CalAge(ByVal birthDate As DateTime) As Integer
		Dim years As Integer = DateTime.Now.Year - birthDate.Year
		If DateTime.Now.Month < birthDate.Month Or (DateTime.Now.Month = birthDate.Month And DateTime.Now.Day < birthDate.Day) Then
			years = years - 1
		End If
		Return years
	End Function

	Public Shared Function ConvertDateToString(ByVal dte As DateTime) As String
		Return dte.ToString("dd/MM/yyyy", New Globalization.CultureInfo("en-GB"))
	End Function

	Public Shared Function ConvertDate(ByVal strDte As String) As Nullable(Of Date)

		Dim rslt As Date
		If Date.TryParseExact(strDte, "dd/MM/yyyy", New System.Globalization.CultureInfo("th-TH"), System.Globalization.DateTimeStyles.None, rslt) Then
			Return rslt
		Else
			Return Nothing
		End If

	End Function

End Class
